import {
    Card,
    Col,
    Form,
    Row,
    Input,
    Radio,
    Button,
    message
} from "antd";
import { useState } from "react";
import { useNavigate } from "react-router-dom";
import { addBookAPI } from "../../../apis/novel";   // 引入小说API

const { TextArea } = Input;
// 类型配置
const typeOptions = [
    { label: '武侠', value: '武侠' },
    { label: '悬疑', value: '悬疑' },
    { label: '科幻', value: '科幻' },
    { label: '现代', value: '现代' },
    { label: '言情', value: '言情' },
    { label: '恐怖', value: '恐怖' },
    { label: '穿越', value: '穿越' },
    { label: '玄幻', value: '玄幻' },
    { label: '仙侠', value: '仙侠' },
    { label: '官场', value: '官场' },
    { label: '职场', value: '职场' },
    { label: '宫斗', value: '宫斗' },
];

// 样式配置
const styleOptions = [
    { label: '简洁明了', value: '简洁明了' },
    { label: '叙事复杂', value: '叙事复杂' },
    { label: '浪漫主义', value: '浪漫主义' },
    { label: '现实主义', value: '现实主义' },
    { label: '诙谐幽默', value: '诙谐幽默' },
    { label: '异想天开', value: '异想天开' },
    { label: '古典主义', value: '古典主义' },
];



const NovelCreationDrawPage = () => {

    const navigate = useNavigate();


    // 表单数据
    const [formData, setFormData] = useState({
        title: '',
        type: '',
        introduction: '',
    })

    // 修改小说名
    const changeTitle = (e) => {
        setFormData({
            ...formData,
            title: e.target.value
        })
    }

    // 修改类型
    const changeType = (e) => {
        setFormData({
            ...formData,
            type: e.target.value
        })
    }

    // 修改简介
    const changeIntroduction = (e) => {
        setFormData({
            ...formData,
            introduction: e.target.value
        })
    }




    // 立即生成
    const startDraw = async () => {
        console.log(formData);

        let res = await addBookAPI(formData);
        console.log('新增书籍',res);
        if (res.code === '0000') {
            message.success('新增书籍成功');
            navigate('/workplace/NovelCreation')
        }else{
            message.error(res.msg);
        }
        
    }


    return (
        <>
            <Card
                style={{
                    height: "calc(100vh - 75px)"
                }}
                title={'写小说'}
            >
                <Row>
                    <Col>
                        <div className={'myform'}>
                            <Form
                                layout={'vertical'}
                            >
                                <Form.Item
                                    label="小说名"
                                    style={{
                                        width: 200
                                    }}
                                >
                                    <Input onChange={changeTitle} value={formData.title} placeholder="请输入小说名" />
                                </Form.Item>

                                <Form.Item
                                    label="类型"
                                >
                                    <Radio.Group onChange={changeType} optionType="button" options={typeOptions} value={formData.type} >
                                    </Radio.Group>
                                </Form.Item>

                                <Form.Item
                                    label="简介"
                                >
                                    <TextArea onChange={changeIntroduction} rows={4} />
                                </Form.Item>

                            </Form>
                        </div>
                        <Button type='primary' onClick={startDraw}>立即生成</Button>
                    </Col>
                </Row>
            </Card>
        </>
    )
}

export default NovelCreationDrawPage